package com.cn.jx.manager.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.cn.jx.manager.po.UserOrgJob;

/**
 * <p>UserOrgJobRepository 用户组织岗位关系操作mapper层操作数据库的接口
 * 
 * @author <h1>jiangxu2  2019年11月21日</h1>
 * @version v1.11.20.2019
 * @since 1.0
 * 
 */
public interface UserOrgJobRepository extends JpaRepository<UserOrgJob,String>,JpaSpecificationExecutor<UserOrgJob>{
	
	/**<p>定义HQL查询 根据用户id查询这个用户的主岗和主组织 {@link UserOrgJob} <p>major=1表示主要服务的组织和主要岗位*/
	@Query(" from UserOrgJob  where userId=:userId and major=1 ")
	public UserOrgJob findUserOrgJobMajorByUserId(@Param(value = "userId") String userId);
	
	/**<p>定义HQL查询 根据用户id这个人所在所有岗位组织 {@link UserOrgJob}*/
	@Query(" from UserOrgJob  where userId=:userId ")
	public List<UserOrgJob> findUserOrgJobByUserId(@Param(value = "userId") String userId);
	
	/**<p>定义HQL查询 根据人员id删除关联关系 {@link UserOrgJob}*/
	@Modifying
	@Query("delete UserOrgJob rc where rc.userId in(:uids) ")
	public void deleteRealationByUserIds(@Param(value="uids") List<String> uids);
	
	/**<p>定义HQL查询 根据岗位id删除关联关系 {@link UserOrgJob}*/
	@Modifying
	@Query("delete UserOrgJob rc where rc.jobId in(:jids) ")
	public void deleteRealationByJobId(@Param(value="jids") List<String> jids);
	
	/**<p>定义HQL查询 根据岗位id删除关联关系 {@link UserOrgJob}*/
	@Modifying
	@Query("delete UserOrgJob rc where rc.orgId in (:oids) ")
	public void deleteRealationByOrgId(@Param(value="oids") List<String> oids);
	
	@Modifying
	@Query("delete UserOrgJob where orgId =:orgid and userId=:userid ")
	public void deleteRealationByOrgIdAndUserId(@Param(value = "orgid") String orgid,@Param(value = "userid") String userid);
	
	@Modifying
	@Query("update UserOrgJob set major=0 where userId=:userid ")
	public void updateUOJmajorRemove(@Param(value = "userid") String userid);
	
	@Modifying
	@Query("update UserOrgJob set major=1 where orgId =:orgid and userId=:userid and jobId=:jobid ")
	public void updateUOJmajorSet(@Param(value = "orgid") String orgid,@Param(value = "userid") String userid,@Param(value = "jobid") String jobid);
	
}
